package com.base.system.controller;

import com.base.system.base.http.HttpResult;
import com.base.system.bean.LoginForm;
import com.base.system.service.EntranceService;
import com.base.system.util.RedisKey;
import com.base.system.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Api(tags = "登录区")
@RestController
@RequestMapping("/entr")
public class EntranceController {
    @Autowired
    private EntranceService entranceService;
    @Autowired
    private RedisUtil redisUtil;

    @PostMapping("/login")
    @ApiOperation(value = "pc端登录，成功登录后返回token")
    public HttpResult<String> login(@RequestBody LoginForm form, HttpSession session) {
        return HttpResult.ok(entranceService.login(form, session));
    }

    @ApiOperation(value = "登出")
    @PostMapping("/logout/{id}")
    public HttpResult<Void> logout(@PathVariable Long id) {
        redisUtil.del(id + RedisKey.USER_MENU);
        return HttpResult.ok();
    }
}
